# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xa269fec>}
nname: 0
n 0(None)[return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xa269f6c>}
nname: 41
n 41(None)[return u''
]:
	i: 24(), 37()
	o: 

nname: 37
n 37(None)[]:
	i: 0&9(f)
	o: 41()

nname: 24
n 24(None)[]:
	i: 0&9(t)
	o: 41()

nname: 0&9
n 0&9(self.selected and user_config['photo']['filename'])[]:
	i: 
	o: 24(t), 37(f)

nname: 0&9
n 0&9(None)[if self.selected and user_config['photo']['filename']:
	pass
return u''
]:
	i: 
	o: 

self.nodes: {'0&9': <unpyclib.structure.node instance at 0xa2713cc>}
nname: 0
n 0(None)[Player.__init__(self, 'imageviewer')
self.eventhandler = ImageEventHandler(self)
self._getitems_keywords.update(item_name=(lambda : .selected and user_config['photo']['filename']:
	pass
return u''), picture_1=(lambda : None), picture_2=(lambda : None))
self.tasks.update({'display_timer': Task(self.play_next), 'select_next': Task(self.select, 1), 'transition': Task(self._transition)})
self.tasks['transition'].delay = 0
self.speed = 1
self._paused = True
self.direction = 1
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xa26976c>}
nname: 20
n 20(None)[return 'play'
]:
	i: 0&9(t), 16()
	o: 

nname: 16
n 16(None)[]:
	i: 0&9(f)
	o: 20()

nname: 0&9
n 0&9(self.paused and 'pause')[]:
	i: 
	o: 16(f), 20(t)

nname: 0&9
n 0&9(None)[if not(self.paused and 'pause'):
	pass
return 'play'
]:
	i: 
	o: 

self.nodes: {'0&9': <unpyclib.structure.node instance at 0xb76cb90c>}
nname: 0
n 0(None)[return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cb7ec>}
nname: 0
n 0(None)[self.tasks['select_next'].start(user_config['photo']['period'])
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cbb4c>}
nname: 0
n 0(None)[return self._paused
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cb78c>}
nname: 47
n 47(None)[louie_send('status_icon', sender=self, value=self._get_status_icon())
]:
	i: 15(), 36()
	o: 

nname: 36
n 36(None)[self._select_next()
]:
	i: 0(f)
	o: 47()

nname: 15
n 15(None)[self.tasks['select_next'].stop()
]:
	i: 0(t)
	o: 47()

nname: 0
n 0(val)[self._paused = val
]:
	i: 
	o: 15(t), 36(f)

nname: 0
n 0(None)[self._paused = val
if val:
	self.tasks['select_next'].stop()
else:
	self._select_next()
louie_send('status_icon', sender=self, value=self._get_status_icon())
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cbcac>}
nname: 127
n 127(None)[]:
	i: 96(AE)
	o: 

nname: 96
n 96(None)[louie_send('picture_%d' % pos[1], sender=self, rotate=angle)
]:
	i: 0(finally), 9()
	o: 127(AE)

nname: 9
n 9(None)[unref_link = 'refid' in self.selected.wymedia_resource
rot = int(self.selected.wymedia_resource.get('rotation', '0'))
self.selected.vfs_set_metas(_unref_link=unref_link, rotation=str(rot + angle))
]:
	i: 0(ASF)
	o: 96()

nname: 0
n 0(None)[rot = 0
]:
	i: 
	o: 9(ASF), 96(finally)

nname: 96
n 96(None)[finally:
	louie_send('picture_%d' % pos[1], sender=self, rotate=angle)
]:
	i: 0()
	o: 

nname: 0
n 0(None)[rot = 0
try:
	unref_link = 'refid' in self.selected.wymedia_resource
	rot = int(self.selected.wymedia_resource.get('rotation', '0'))
	self.selected.vfs_set_metas(_unref_link=unref_link, rotation=str(rot + angle))
]:
	i: 
	o: 96()

nname: 0
n 0(None)[rot = 0
try:
	unref_link = 'refid' in self.selected.wymedia_resource
	rot = int(self.selected.wymedia_resource.get('rotation', '0'))
	self.selected.vfs_set_metas(_unref_link=unref_link, rotation=str(rot + angle))
finally:
	louie_send('picture_%d' % pos[1], sender=self, rotate=angle)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cbdcc>}
nname: 157
n 157(None)[return None
]:
	i: 3(), 70(), 129(), 156(AE)
	o: 

nname: 129
n 129(None)[PRINT_EXCEPTION()
log.error('Unable to display this image')
]:
	i: 60(f)
	o: 157()

nname: 70
n 70(None)[#, e
from pygui.window import MessageWindow
MessageWindow(_('Invalid picture'), button=None).show(timeout=5)
]:
	i: 60(t)
	o: 157()

nname: 60
n 60(<dummy_ex3> EXC_MATCH IOError)[]:
	i: 0(except)
	o: 70(t), 129(f)

nname: 3
n 3(None)[louie_send('picture_%d' % pos[0], sender=self, value=self.selected['uri'], callback=self.tasks['transition'].start)
]:
	i: 0(try)
	o: 157()

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 60(except)

nname: 60
n 60(None)[except IOError, e:
	from pygui.window import MessageWindow
	MessageWindow(_('Invalid picture'), button=None).show(timeout=5)
except:
	PRINT_EXCEPTION()
	log.error('Unable to display this image')
return None
]:
	i: 0()
	o: 

nname: 0
n 0(None)[try:
	louie_send('picture_%d' % pos[0], sender=self, value=self.selected['uri'], callback=self.tasks['transition'].start)
]:
	i: 
	o: 60()

nname: 0
n 0(None)[try:
	louie_send('picture_%d' % pos[0], sender=self, value=self.selected['uri'], callback=self.tasks['transition'].start)
except IOError, e:
	from pygui.window import MessageWindow
	MessageWindow(_('Invalid picture'), button=None).show(timeout=5)
except:
	PRINT_EXCEPTION()
	log.error('Unable to display this image')
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xa26960c>}
nname: 36
n 36(None)[rot = int(self.selected['rotation'])
log.info('rotation=%i', rot)
louie_send('picture_%i' % pos[0], sender=self, rotate=rot)
]:
	i: 0(t), 32()
	o: 

nname: 32
n 32(None)[]:
	i: 0(f)
	o: 36()

nname: 0
n 0(self.selected['rotation'])[self.selected.media_update('rotation')
]:
	i: 
	o: 32(f), 36(t)

nname: 0
n 0(None)[self.selected.media_update('rotation')
if not self.selected['rotation']:
	pass
rot = int(self.selected['rotation'])
log.info('rotation=%i', rot)
louie_send('picture_%i' % pos[0], sender=self, rotate=rot)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cbecc>}
nname: 62
n 62(None)[log.debug('picture=%s uri=%s anim=%s', self.selected, self.selected['uri'], anim)
self._apply_rotation()
louie_send('%s_A_%d' % (direction, pos[0]), sender=self)
louie_send('%s_B_%d' % (direction, pos[1]), sender=self)
pos.reverse()
]:
	i: 29(), 47()
	o: 

nname: 47
n 47(None)[direction = SYMETRIC_DIRECTION['up'][anim]
]:
	i: 0(f)
	o: 62()

nname: 29
n 29(None)[direction = SYMETRIC_DIRECTION['down'][anim]
]:
	i: 0(t)
	o: 62()

nname: 0
n 0(self.direction > 0)[anim = user_config['photo']['transition']
]:
	i: 
	o: 29(t), 47(f)

nname: 0
n 0(None)[anim = user_config['photo']['transition']
if self.direction > 0:
	direction = SYMETRIC_DIRECTION['down'][anim]
else:
	direction = SYMETRIC_DIRECTION['up'][anim]
log.debug('picture=%s uri=%s anim=%s', self.selected, self.selected['uri'], anim)
self._apply_rotation()
louie_send('%s_A_%d' % (direction, pos[0]), sender=self)
louie_send('%s_B_%d' % (direction, pos[1]), sender=self)
pos.reverse()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xa2695cc>}
nname: 0
n 0(None)[self.paused = not self.paused
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cb76c>}
nname: 43
n 43(None)[Player.stop(self, *args, **kw)
return None
]:
	i: 0(AL), 42()
	o: 

nname: 42
n 42(None)[]:
	i: 3(AF), 10()
	o: 43()

nname: 10
n 10(None)[for i in pos:
louie_send('picture_%d' % i, sender=self, value=None)
]:
	i: 3(for)
	o: 42()

nname: 3
n 3(None)[]:
	i: 0(loop)
	o: 10(for), 42(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 3(loop), 43(AL)

nname: 43
n 43(None)[Player.stop(self, *args, **kw)
return None
]:
	i: 10()
	o: 

nname: 10
n 10(None)[for i in pos:
	louie_send('picture_%d' % i, sender=self, value=None)
]:
	i: 0(for)
	o: 43()

nname: 0
n 0(None)[]:
	i: 
	o: 10(for)

nname: 43
n 43(None)[Player.stop(self, *args, **kw)
return None
]:
	i: 0()
	o: 

nname: 0
n 0(None)[for i in pos:
	louie_send('picture_%d' % i, sender=self, value=None)
]:
	i: 
	o: 43()

nname: 0
n 0(None)[for i in pos:
	louie_send('picture_%d' % i, sender=self, value=None)
Player.stop(self, *args, **kw)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cbecc>}
nname: 34
n 34(None)[]:
	i: 19(), 33()
	o: 

nname: 33
n 33(None)[]:
	i: 0(t)
	o: 34()

nname: 19
n 19(None)[self._select_next()
]:
	i: 0(f)
	o: 34()

nname: 0
n 0(self._paused)[self._display_picture()
]:
	i: 
	o: 19(f), 33(t)

nname: 0
n 0(None)[self._display_picture()
if not self._paused:
	self._select_next()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76cb98c>}
nname: 6
n 6(None)[__doc__ = 'Image player.'
def __init__(self):
	Player.__init__(self, 'imageviewer')
	self.eventhandler = ImageEventHandler(self)
	self._getitems_keywords.update(item_name=(lambda : .selected and user_config['photo']['filename']:
		pass
	return u''), picture_1=(lambda : None), picture_2=(lambda : None))
	self.tasks.update({'display_timer': Task(self.play_next), 'select_next': Task(self.select, 1), 'transition': Task(self._transition)})
	self.tasks['transition'].delay = 0
	self.speed = 1
	self._paused = True
	self.direction = 1

def _get_status(self):
	if not(self.paused and 'pause'):
		pass
	return 'play'

def _start_timers(self):
	return None

def _select_next(self):
	self.tasks['select_next'].start(user_config['photo']['period'])

def _get_paused(self):
	return self._paused

def _set_paused(self, val):
	self._paused = val
	if val:
		self.tasks['select_next'].stop()
	else:
		self._select_next()
	louie_send('status_icon', sender=self, value=self._get_status_icon())

paused = property(_get_paused, _set_paused, doc='Bool indicating if player is paused or not')
del _get_paused
del _set_paused
play = selective_gui_updater('item_name')(name_activator())
def rotate(self, angle):
	rot = 0
	try:
		unref_link = 'refid' in self.selected.wymedia_resource
		rot = int(self.selected.wymedia_resource.get('rotation', '0'))
		self.selected.vfs_set_metas(_unref_link=unref_link, rotation=str(rot + angle))
	finally:
		louie_send('picture_%d' % pos[1], sender=self, rotate=angle)

def _display_picture(self):
	try:
		louie_send('picture_%d' % pos[0], sender=self, value=self.selected['uri'], callback=self.tasks['transition'].start)
	except IOError, e:
		from pygui.window import MessageWindow
		MessageWindow(_('Invalid picture'), button=None).show(timeout=5)
	except:
		PRINT_EXCEPTION()
		log.error('Unable to display this image')
	return None

def _apply_rotation(self):
	self.selected.media_update('rotation')
	if not self.selected['rotation']:
		pass
	rot = int(self.selected['rotation'])
	log.info('rotation=%i', rot)
	louie_send('picture_%i' % pos[0], sender=self, rotate=rot)

def _transition(self):
	anim = user_config['photo']['transition']
	if self.direction > 0:
		direction = SYMETRIC_DIRECTION['down'][anim]
	else:
		direction = SYMETRIC_DIRECTION['up'][anim]
	log.debug('picture=%s uri=%s anim=%s', self.selected, self.selected['uri'], anim)
	self._apply_rotation()
	louie_send('%s_A_%d' % (direction, pos[0]), sender=self)
	louie_send('%s_B_%d' % (direction, pos[1]), sender=self)
	pos.reverse()

def toggle_pause(self):
	self.paused = not self.paused

def stop(self, *args, **args):
	for i in pos:
		louie_send('picture_%d' % i, sender=self, value=None)
	Player.stop(self, *args, **kw)
	return None

def play_next(self):
	self._display_picture()
	if not self._paused:
		self._select_next()

select = selective_gui_updater('item_name')(name_activator())
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76c4c8c>}
nname: 0
n 0(None)[from __future__ import absolute_import
__all__ = ['ImageViewer']
from time import sleep
from peewee.debug import GET_LOGGER, PRINT_EXCEPTION
from peewee.messages import send as louie_send
from peewee.notifier import Task
from pygui.config import user_config, HMI_PHOTO
from pygui.eventmanager.players import ImageEventHandler
from pygui.shared import pygui_globs
from pygui.menu import selective_gui_updater
from pygui.menu.players.core import Player, TimerActivator
from pygui.facilities.codemapping import SYMETRIC_DIRECTION
log = GET_LOGGER(__name__)
class ImageViewer(Player):
	__doc__ = 'Image player.'
	def __init__(self):
		Player.__init__(self, 'imageviewer')
		self.eventhandler = ImageEventHandler(self)
		self._getitems_keywords.update(item_name=(lambda : .selected and user_config['photo']['filename']:
			pass
		return u''), picture_1=(lambda : None), picture_2=(lambda : None))
		self.tasks.update({'display_timer': Task(self.play_next), 'select_next': Task(self.select, 1), 'transition': Task(self._transition)})
		self.tasks['transition'].delay = 0
		self.speed = 1
		self._paused = True
		self.direction = 1

	def _get_status(self):
		if not(self.paused and 'pause'):
			pass
		return 'play'

	def _start_timers(self):
		return None

	def _select_next(self):
		self.tasks['select_next'].start(user_config['photo']['period'])

	def _get_paused(self):
		return self._paused

	def _set_paused(self, val):
		self._paused = val
		if val:
			self.tasks['select_next'].stop()
		else:
			self._select_next()
		louie_send('status_icon', sender=self, value=self._get_status_icon())

	paused = property(_get_paused, _set_paused, doc='Bool indicating if player is paused or not')
	del _get_paused
	del _set_paused
	play = selective_gui_updater('item_name')(name_activator())
	def rotate(self, angle):
		rot = 0
		try:
			unref_link = 'refid' in self.selected.wymedia_resource
			rot = int(self.selected.wymedia_resource.get('rotation', '0'))
			self.selected.vfs_set_metas(_unref_link=unref_link, rotation=str(rot + angle))
		finally:
			louie_send('picture_%d' % pos[1], sender=self, rotate=angle)

	def _display_picture(self):
		try:
			louie_send('picture_%d' % pos[0], sender=self, value=self.selected['uri'], callback=self.tasks['transition'].start)
		except IOError, e:
			from pygui.window import MessageWindow
			MessageWindow(_('Invalid picture'), button=None).show(timeout=5)
		except:
			PRINT_EXCEPTION()
			log.error('Unable to display this image')
		return None

	def _apply_rotation(self):
		self.selected.media_update('rotation')
		if not self.selected['rotation']:
			pass
		rot = int(self.selected['rotation'])
		log.info('rotation=%i', rot)
		louie_send('picture_%i' % pos[0], sender=self, rotate=rot)

	def _transition(self):
		anim = user_config['photo']['transition']
		if self.direction > 0:
			direction = SYMETRIC_DIRECTION['down'][anim]
		else:
			direction = SYMETRIC_DIRECTION['up'][anim]
		log.debug('picture=%s uri=%s anim=%s', self.selected, self.selected['uri'], anim)
		self._apply_rotation()
		louie_send('%s_A_%d' % (direction, pos[0]), sender=self)
		louie_send('%s_B_%d' % (direction, pos[1]), sender=self)
		pos.reverse()

	def toggle_pause(self):
		self.paused = not self.paused

	def stop(self, *args, **args):
		for i in pos:
			louie_send('picture_%d' % i, sender=self, value=None)
		Player.stop(self, *args, **kw)
		return None

	def play_next(self):
		self._display_picture()
		if not self._paused:
			self._select_next()

	select = selective_gui_updater('item_name')(name_activator())


]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76b6f4c>}
from __future__ import absolute_import
__all__ = ['ImageViewer']
from time import sleep
from peewee.debug import GET_LOGGER, PRINT_EXCEPTION
from peewee.messages import send as louie_send
from peewee.notifier import Task
from pygui.config import user_config, HMI_PHOTO
from pygui.eventmanager.players import ImageEventHandler
from pygui.shared import pygui_globs
from pygui.menu import selective_gui_updater
from pygui.menu.players.core import Player, TimerActivator
from pygui.facilities.codemapping import SYMETRIC_DIRECTION
log = GET_LOGGER(__name__)
class ImageViewer(Player):
	__doc__ = 'Image player.'
	def __init__(self):
		Player.__init__(self, 'imageviewer')
		self.eventhandler = ImageEventHandler(self)
		self._getitems_keywords.update(item_name=(lambda : .selected and user_config['photo']['filename']:
			pass
		return u''), picture_1=(lambda : None), picture_2=(lambda : None))
		self.tasks.update({'display_timer': Task(self.play_next), 'select_next': Task(self.select, 1), 'transition': Task(self._transition)})
		self.tasks['transition'].delay = 0
		self.speed = 1
		self._paused = True
		self.direction = 1

	def _get_status(self):
		if not(self.paused and 'pause'):
			pass
		return 'play'

	def _start_timers(self):
		return None

	def _select_next(self):
		self.tasks['select_next'].start(user_config['photo']['period'])

	def _get_paused(self):
		return self._paused

	def _set_paused(self, val):
		self._paused = val
		if val:
			self.tasks['select_next'].stop()
		else:
			self._select_next()
		louie_send('status_icon', sender=self, value=self._get_status_icon())

	paused = property(_get_paused, _set_paused, doc='Bool indicating if player is paused or not')
	del _get_paused
	del _set_paused
	play = selective_gui_updater('item_name')(name_activator())
	def rotate(self, angle):
		rot = 0
		try:
			unref_link = 'refid' in self.selected.wymedia_resource
			rot = int(self.selected.wymedia_resource.get('rotation', '0'))
			self.selected.vfs_set_metas(_unref_link=unref_link, rotation=str(rot + angle))
		finally:
			louie_send('picture_%d' % pos[1], sender=self, rotate=angle)

	def _display_picture(self):
		try:
			louie_send('picture_%d' % pos[0], sender=self, value=self.selected['uri'], callback=self.tasks['transition'].start)
		except IOError, e:
			from pygui.window import MessageWindow
			MessageWindow(_('Invalid picture'), button=None).show(timeout=5)
		except:
			PRINT_EXCEPTION()
			log.error('Unable to display this image')
		return None

	def _apply_rotation(self):
		self.selected.media_update('rotation')
		if not self.selected['rotation']:
			pass
		rot = int(self.selected['rotation'])
		log.info('rotation=%i', rot)
		louie_send('picture_%i' % pos[0], sender=self, rotate=rot)

	def _transition(self):
		anim = user_config['photo']['transition']
		if self.direction > 0:
			direction = SYMETRIC_DIRECTION['down'][anim]
		else:
			direction = SYMETRIC_DIRECTION['up'][anim]
		log.debug('picture=%s uri=%s anim=%s', self.selected, self.selected['uri'], anim)
		self._apply_rotation()
		louie_send('%s_A_%d' % (direction, pos[0]), sender=self)
		louie_send('%s_B_%d' % (direction, pos[1]), sender=self)
		pos.reverse()

	def toggle_pause(self):
		self.paused = not self.paused

	def stop(self, *args, **args):
		for i in pos:
			louie_send('picture_%d' % i, sender=self, value=None)
		Player.stop(self, *args, **kw)
		return None

	def play_next(self):
		self._display_picture()
		if not self._paused:
			self._select_next()

	select = selective_gui_updater('item_name')(name_activator())


